package com.crazyice.lee.reader;

import com.crazyice.lee.data.Order;
import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Random;

public class OrderList extends RichParallelSourceFunction<Order> {
    private boolean isRun=true;
    private DateFormat bf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public void run(SourceContext<Order> sourceContext) throws Exception {
        Random random=new Random();
        int number=1;
        while (isRun){
            Order order=new Order();
            order.setId(String.format("%010d",number++));
            order.setNumber(random.nextInt(100));
            order.setOrderTime(System.currentTimeMillis());
            order.setProductId(String.format("%010d",random.nextInt(100)));
            order.setTotalPrice(0);
            sourceContext.collect(order);
            Thread.sleep(100);
        }

    }

    @Override
    public void cancel() {
        isRun=false;
    }
}
